package cn.yudao.controller;

import cn.yudao.config.httpSendConfig;
import cn.yudao.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
@DefaultProperties
public class OrderController {


    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/getuser/{id}")
    @HystrixCommand(fallbackMethod = "getUserByIdFallbackMethod")
    public User getUserById(@PathVariable Long id){

        String url = "http://user-server/user/getuser/" + id;
        User user = restTemplate.getForObject(url, User.class);
        return user;
    }


    public User getUserByIdFallbackMethod(@PathVariable Long id){

        return new User("李多",8,"吾儿出问题了");
    }

}
